<!--
 @description  配送核心指标统计
 @fileName CoreData.vue
 @author maliang
 @created 2021/09/26 14:05:00
-->
<template>
  <div>
    <div class="core-list">
      <div class="core-item">
        <span class="red-num">{{ todayPlanArriveQuantity }}</span>
        <p>今日计划整车数(车)</p>
      </div>
      <div class="core-item">
        <span class="blue-num">{{ yesterdayArriveQuantity }}</span>
        <p>昨日到车整车数(车)</p>
      </div>
      <div class="core-item">
        <span class="green-num">{{ yesterdayShipQuantity }}</span>
        <p>昨日启运整车数(车)</p>
      </div>
      <div class="core-item">
        <span class="yellow-num">{{ notShipQuantity }}</span>
        <p>累积未启运整车数(车)</p>
      </div>
    </div>
    <div class="core-update-time">统计截止时间: {{ coreDate }} 08:00</div>
  </div>
</template>

<script>
import { parseTime } from '@/utils'
import {
  getDistributionNotShip,
  getDistributionTodayPlanArrive,
  getDistributionYesterdayArrive,
  getDistributionYesterdayShip
} from '@/apis/distribution'
export default {
  name: 'DistributionCoreData',
  props: {
    coreDate: {
      type: String,
      default: parseTime(new Date(), '{y}.{m}.{d}')
    },
    currentCenter: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      todayPlanArriveQuantity: '-', // 今日计划整车数
      yesterdayArriveQuantity: '-', // 昨日到车整车数
      yesterdayShipQuantity: '-', // 昨日启运整车数
      notShipQuantity: '-' // 累计未启运整车数
    }
  },
  watch: {
    currentCenter: {
      handler() {
        this.getCenterTargetData()
      },
      immediate: true
    }
  },
  methods: {
    async getCenterTargetData() {
      const params = {
        center: this.currentCenter
      }
      // 累计未启运整车数
      const notShipQuantity = getDistributionNotShip(params)
      // 今日计划整车数
      const todayPlanArriveQuantity = getDistributionTodayPlanArrive(
        params
      )
      // 昨日到车整车数
      const yesterdayArriveQuantity = getDistributionYesterdayArrive(
        params
      )
      // 昨日启运整车数
      const yesterdayShipQuantity = getDistributionYesterdayShip(params)
      try {
        const [
          notShipQuantityRes,
          todayPlanArriveQuantityRes,
          yesterdayArriveQuantityRes,
          yesterdayShipQuantityRes
        ] = await Promise.all([
          notShipQuantity,
          todayPlanArriveQuantity,
          yesterdayArriveQuantity,
          yesterdayShipQuantity
        ])
        this.notShipQuantity = notShipQuantityRes.data
          ? notShipQuantityRes.data[0].notShipQuantity
          : '-'
        this.todayPlanArriveQuantity = todayPlanArriveQuantityRes.data
          ? todayPlanArriveQuantityRes.data[0].todayPlanArriveQuantity
          : '-'
        this.yesterdayArriveQuantity = yesterdayArriveQuantityRes.data
          ? yesterdayArriveQuantityRes.data[0].yesterdayArriveQuantity
          : '-'
        this.yesterdayShipQuantity = yesterdayShipQuantityRes.data
          ? yesterdayShipQuantityRes.data[0].yesterdayShipQuantity
          : ''
      } catch (error) {
        this.$toast.fail('系统异常')
      }
    }
  }
}
</script>
<style lang="less" scoped>
.core-list {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    &::after {
        position: absolute;
        left: 0;
        top: 0;
        content: "";
        width: 100%;
        height: 2px;
        background-color: #f5f6f7;
        transform: scaleY(0.5);
    }
    .core-item {
        position: relative;
        width: 50%;
        height: 84px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        &::after {
            position: absolute;
            left: 0;
            bottom: 0;
            content: "";
            width: 100%;
            height: 2px;
            background-color: #f5f6f7;
            transform: scaleY(0.5);
        }
        &:nth-child(even) {
            &::before {
                position: absolute;
                left: -1px;
                top: 50%;
                content: "";
                width: 2px;
                height: 54px;
                background-color: #f5f6f7;
                transform: scaleX(0.5);
                margin-top: -27px;
            }
        }
        > span {
            font-size: 22px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: bold;
            line-height: 28px;
            letter-spacing: 1px;
        }
        .red-num {
            color: #f15643;
        }
        .blue-num {
            color: #3d98f1;
        }
        .green-num {
            color: #12b9a3;
        }
        .yellow-num {
            color: #ffc14a;
        }
        > p {
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 16px;
            letter-spacing: 1px;
            margin-top: 10px;
        }
    }
}
.core-update-time {
    line-height: 18px;
    text-align: center;
    color: #999999;
    letter-spacing: 1px;
    font-size: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
}
/deep/ .van-action-sheet__name {
    color: #333333;
    font-size: 16px;
}
</style>
